package com.efounder.frame.title;

import androidx.fragment.app.Fragment;
import android.view.View;

/**
 * Created by XinQing on 2016/12/6.
 */

public class EFTitleViewUtils {

    public static EFTitleView getEFTitleView(Fragment fragment){
        //1.从fragment中获取TitleView
        if (fragment.getParentFragment() != null && fragment.getParentFragment() instanceof EFTitleViewInterface){
            EFTitleViewInterface titleViewInterface = (EFTitleViewInterface) fragment.getParentFragment();
            EFTitleView titleView = titleViewInterface.getEFTitleView();
            if (titleView != null && titleView.getVisibility() == View.VISIBLE){
                return titleView;
            }
        }
        //2.从Activity中获取TitleView
        if (fragment.getActivity() != null && fragment.getActivity() instanceof EFTitleViewInterface){
            EFTitleViewInterface titleViewInterface = (EFTitleViewInterface) fragment.getActivity();
            EFTitleView titleView = titleViewInterface.getEFTitleView();
            if (titleView != null && titleView.getVisibility() == View.VISIBLE){
                return titleView;
            }
        }

        return null;
    }

}
